using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using DocToolTipLib.Generics;

namespace DocToolTipLib
{
  public class DocToolTipHelper : Singleton<DocToolTipHelper>
  {
    private FrmDocManager _frmDocManager;

    public DocToolTipHelper()
    {
      _frmDocManager = new FrmDocManager();      
    }

    public Control MainControl
    {
      get { return _frmDocManager.MainControl; }
      set
      {
        _frmDocManager.MainControl = value;
      }
    }

    public void AddControl(Control control)
    {
      _frmDocManager.AddControl(control);

      control.HandleDestroyed += new EventHandler(control_HandleDestroyed);
    }

    void control_HandleDestroyed(object sender, EventArgs e)
    {
      Control control = sender as Control;
      if (control != null)
      {
        control.HandleDestroyed -= control_HandleDestroyed;

        _frmDocManager.RemoveControl(control);
        if (_frmDocManager.MainControl == control)
        {
          _frmDocManager.MainControl = null;
        }
      }
     
    }


  }
}
